package com.wpp.mq.rabbitmqsqmple.topic;

import com.rabbitmq.client.*;
import com.wpp.mq.rabbitmqsqmple.factory.MyConnectionFactoryBuilder;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @description: 消费者
 *  消费 速度慢的 所有消息
 * @author: WangPengPeng
 * @create: 2021-11-28 22:23
 **/
public class ReceiveLazyLogsTopic {
    private static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = MyConnectionFactoryBuilder.buildConnection();

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        String queueName = channel.queueDeclare().getQueue();
        channel.queueBind(queueName, EXCHANGE_NAME, "lazy.#");
        DeliverCallback callback = (consumerTag, message) -> {
            System.out.println("lazy.*.* 匹配到的消息：" + new String(message.getBody(), "UTF-8"));
        };
        channel.basicConsume(queueName, true, callback, consumerTag -> {
        });
    }
}
